package cn.wolfcode.car.controller;


import cn.wolfcode.car.domain.Business;
import cn.wolfcode.car.enumpkg.ConsumptionStatusEnum;
import cn.wolfcode.car.qo.BusinessReportQueryObject;
import cn.wolfcode.car.service.IBusinessService;
import cn.wolfcode.car.service.IConsumptionService;
import cn.wolfcode.car.vo.BusinessReportVO;
import cn.wolfcode.car.vo.ChartVO;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;


@Controller
@RequestMapping("/report")
public class BusinessReportController {
    @Autowired
    private IConsumptionService consumptionService;
    @Autowired
    private IBusinessService businessService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") BusinessReportQueryObject qo) {

        PageInfo<BusinessReportVO> list = consumptionService.selectByGroup(qo);
        model.addAttribute("result", list);
        List<Business> businesses = businessService.listAll();
        model.addAttribute("businesses", businesses);
        ConsumptionStatusEnum[] values = ConsumptionStatusEnum.values();
        model.addAttribute("status", values);



        List<BusinessReportVO> all = consumptionService.selectByGroupNotLimit(qo);
        ChartVO chartVO = new ChartVO();
        for (int i = 0; i < all.size(); i++) {
            BusinessReportVO reportVO = all.get(i);
            chartVO.getCond().add(reportVO.getCond());
            chartVO.getCount().add(reportVO.getCount());
            chartVO.getPay().add(reportVO.getPay());
            chartVO.getDiscount().add(reportVO.getDiscount());
            chartVO.getTotal().add(reportVO.getTotal());
        }
        System.out.println(JSON.toJSONString(chartVO));
        model.addAttribute("chart", chartVO);


        return "businessReport/list";
    }
}
